package logic

import (
	"context"
	"wechatdev/wechatdevrpc/wechatdevrpc"

	"wechatdev/api/internal/svc"
	"wechatdev/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdataLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewUpdataLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdataLogic {
	return &UpdataLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *UpdataLogic) Updata(req *types.UpdataRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	perfacet, err := l.svcCtx.WechatDevRpc.Perfacet(l.ctx, &wechatdevrpc.PerfacetRequest{
		UserId:    int64(req.UserId),
		HeadImage: req.HeadImage,
		Address:   req.Address,
		NickName:  req.NickName,
		Mobile:    req.Mobile,
		Password:  req.Password,
		Qq:        req.Qq,
		WxCode:    req.WxCode,
		Email:     req.Email,
	})
	if err != nil {
		return &types.Response{
			Message: "修改失败",
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "修改成功",
		Code:    200,
		Data:    perfacet,
	}, nil
}
